//
//  LocalData.m
//  SDK_OpenSDK
//
//  Created by 涂俊 on 2018/5/4.
//  Copyright © 2018年 wyht. All rights reserved.
//

#import "LocalData.h"

@implementation LocalData

static LocalData *instance = nil;

NSString * const SLocalRoleID=@"role_id";
NSString * const SLocalRoleName=@"role_name";
NSString * const SLocalRoleGrade=@"role_grade";
NSString * const SLocalRoleBalance=@"role_balance";
NSString * const SLocalSuperSDKUID=@"supersdk_uid";
NSString * const SLocalGameUID=@"game_uid";
NSString * const SLocalServerID=@"server_id";
NSString * const SLocalAppData=@"app_data";
NSString * const SLocalUserData=@"SuperSDKForOpenSDKUserData";

+ (id) getInstance {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[self alloc] init];
    });
    return instance;
}

+ (void) saveCurUser:(NSString *)RoleID RoleName:(NSString *)RoleName RoleGrade:(NSString *)RoleGrade RoleBalance:(NSString *)RoleBalance SuperSDKUID:(NSString *)SuperSDKUID GameUID:(NSString *)GameUID ServerID:(NSString *)ServerID AppData:(NSString *)AppData {
    NSMutableDictionary *userData = [[NSMutableDictionary alloc] init];
    [userData setObject:RoleID forKey:SLocalRoleID];
    [userData setObject:RoleName forKey:SLocalRoleName];
    [userData setObject:RoleBalance forKey:SLocalRoleBalance];
    [userData setObject:RoleGrade forKey:SLocalRoleGrade];
    [userData setObject:SuperSDKUID forKey:SLocalSuperSDKUID];
    [userData setObject:GameUID forKey:SLocalGameUID];
    [userData setObject:ServerID forKey:SLocalServerID];
    [userData setObject:AppData forKey:SLocalAppData];
    [[NSUserDefaults standardUserDefaults] setObject:userData forKey:SLocalUserData];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (NSMutableDictionary *) getCurUser {
    NSDictionary *localData = [[NSUserDefaults standardUserDefaults] dictionaryForKey:SLocalUserData];
    return localData == nil ? nil : [NSMutableDictionary dictionaryWithDictionary:localData];
}

+ (void) delLocalData {
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:SLocalUserData];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

@end
